package controller;
import java.util.ArrayList;

import db.DBUser;

import model.*;

public class UserController {
	private String currentUserId;

	
	
	private static UserController userController = null;
    /** Making the class private as per the singleton pattern */
    private UserController(){
    
    }
    /** Creating an instance of the class*/
    public static UserController getInstance(){
            if(userController == null){
                    userController = new UserController();
            }
            return userController;
    }

	

	public ArrayList<User> findAllUsers(){
		DBUser dbuser = new DBUser();
		ArrayList<User> allUsers = new ArrayList<User>();
		allUsers = dbuser.getAllUsers(false);

		return allUsers;
	}

	public User findbyUserid(String userId){
		DBUser dbuser = new DBUser();
		return dbuser.findUser(userId, true);		
	}

	public User findByFname(String fname){
		DBUser dbuser = new DBUser();
		return dbuser.searchUserFname(fname, true);
	}

	public User findByLname(String lname){
		DBUser dbuser = new DBUser();
		return dbuser.searchUserLname(lname, true);
	}

	public int updateUser(String userId, String fname, String lname, String dateOfbirth, double height, double weight, String gender){
		DBUser dbuser = new DBUser();
		User user = User.getInstance();
		user.setUserId(userId);
		user.setFname(fname);
		user.setLname(lname);
		user.setDateOfBirth(dateOfbirth);
		user.setHeight(height);
		user.setWeight(weight); 
		user.setGender(gender);

		return dbuser.updateUser(user);
	}

	public void insertNew(String userId, String fname, String lname,String dateOfbirth, double height, double weight, String gender){
		DBUser dbuser = new DBUser();
		User user = new User();
		user.setUserId(userId);
		user.setFname(fname);
		user.setLname(lname);
		user.setDateOfBirth(dateOfbirth);
		user.setHeight(height);
		user.setWeight(weight);
		user.setGender(gender);
		dbuser.insertUser(user);
	}

	public void deleteUser(String userId){
		DBUser dbuser = new DBUser();
		dbuser.delete(userId);

	}

	public String getCurrentUser(){
		return this.currentUserId;
	}
	
	public void setCurrentUserId(String userId){
		this.currentUserId = userId;
	}
	

}
